package com.softserve.academy.food.services;

import java.util.ArrayList;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.softserve.academy.food.dao.HibernateDish;
import com.softserve.academy.food.entity.eDish;
import com.softserve.academy.food.model.mDish;

@Service
public class ViewDish implements iViewDish
{
	@Autowired
	private HibernateDish daoDish;
	
	private ArrayList<mDish> list = new ArrayList<mDish>();
	
	public ArrayList<mDish> getDishs()
	{
		return list;
	}
	
	@Override
    @Transactional
	public void setAll()
	{
		ArrayList<mDish> list = new ArrayList<mDish>();
		ArrayList<eDish> elist = daoDish.ReadAll();
		
		for (eDish dish : elist)
		{
			list.add( new mDish( dish ) );
		}
		this.list = list;
	}
	
	@Override
	@Transactional
	public ArrayList<mDish> getDishesByIds( ArrayList<Integer> idList )
	{
		ArrayList<mDish> list = new ArrayList<mDish>();
		
		for (eDish dish : daoDish.getDishesByIds(idList))
		{
			list.add( new mDish( dish ) );
		}
		
		return list;
	}
	
	@Override
	@Transactional
	public void setType( int id )
	{
		ArrayList<mDish> list = new ArrayList<mDish>();
		ArrayList<eDish> elist = daoDish.getDishesByType(id);
		
		for (eDish dish : elist)
		{
			list.add( new mDish( dish ) );
		}
		this.list = list;
	}

}
